﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms
{
    public partial class CheckBoxDemo : Form
    {
        public CheckBoxDemo()
        {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = "姓名：" + txtName.Text + "\n";
            //运用MessageBox的构造方法，对MessageBox的标题、图标MessageBoxIcon、按钮MessageBoxButtons进行设计。
            DialogResult result = MessageBox.Show(str, "请确认信息是否正确", MessageBoxButtons.OKCancel, MessageBoxIcon.Information,MessageBoxDefaultButton.Button1);
            if(result==DialogResult.OK)
            {
                txtName.Clear();
                chkMusic.Checked = false;
                chkSport.Checked = false;
                chkMovie.Checked = false;
            } 
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtName_Validating(object sender, CancelEventArgs e)
        {
            if(txtName.Text.Trim()==string.Empty)
            {
                MessageBox.Show("姓名不能为空！");
                txtName.Focus();
            }
        }
        //设计该事件目的：在退出时不引发TextBox控件的Validating事件，防止多余提示。
        private void btnExit_MouseEnter(object sender, EventArgs e)
        {
            txtName.CausesValidation = false;
        }
        //设计该事件目的：恢复TextBox控件的Validating事件。
        private void btnExit_MouseLeave(object sender, EventArgs e)
        {
            txtName.CausesValidation = true;
        }
    }
}
